package cn.dengta.webapp.trade.dto;

import java.util.Date;
import javax.annotation.Nullable;

import cn.dengta.common.context.RequestContext;
import cn.dengta.webapp.base.entity.BaseEntity;
import cn.dengta.webapp.trade.model.TradeType;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
public abstract class TradeDTO<N extends Number> {

	/** 交易发起方的用户ID(【发起方】) */
	protected Long fromUserId;
	/** 【发起方】主观认为的资金交易类型 */
	protected TradeType tradeType;
	/** 本次交易的另一交互方(【关联/接收方】) */
	@Nullable
	protected Long toUserId;
	/** 本次交易的交易额度 */
	protected N tradeAmount;
	/** 【发起方】主观认为的本次资金交易所关联的事物类型(因为什么事物而产生该笔交易) */
	protected BaseEntity assocObj;
	/** 备注 */
	@Nullable
	protected String remark;

	protected String ip;
	protected Date now;

	public void init(Long fromUserId, TradeType tradeType, @Nullable Long toUserId, N tradeAmount, BaseEntity assocObj) {
		this.fromUserId = fromUserId;
		this.tradeType = tradeType;
		this.toUserId = toUserId;
		this.tradeAmount = tradeAmount;
		this.assocObj = assocObj;
	}

	public void init(String ip, Date now) {
		this.ip = ip;
		this.now = now;
	}

	public void init(RequestContext req) {
		this.ip = req.clientIP();
		this.now = req.now();
	}

}

